package master.photo.service.impl;

import java.util.List;

import master.photo.dao.GenericDAO;
import master.photo.domain.security.AppUser;
import master.photo.service.FriendFinderService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class FriendFinderServiceImpl implements FriendFinderService {

	@Autowired
	private GenericDAO genericDAO;

	@Override
	public List<AppUser> findFriends(Long userId) {
		String sql = "select au.* from app_user au "
				+ "join app_user_app_user au_au on (au.id = au_au.app_user_friends_id) "
				+ "where au_au.app_user_id = " + userId
				+ "union "
				+ "select au.* from app_user au "
				+ "join app_user_app_user au_au on (au.id = au_au.app_user_id) "
				+ "where au_au.app_user_friends_id = " + userId;
		return genericDAO.listByNativeSQL(AppUser.class, sql);
	}

}
